package com.superteam.zzl.view;

import android.app.Activity;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.superteam.zzl.activity.MineActivity.LoginActivity;
import com.superteam.zzl.activity.MineActivity.SettingActivity;
import com.superteam.zzl.activity.R;
import com.superteam.zzl.activity.databinding.MinefragmentLayoutBinding;
import com.superteam.zzl.app.MyApplication;
import com.superteam.zzl.utils.ScreenUtils;

import com.superteam.zzl.activity.R;
import com.superteam.zzl.activity.databinding.MinefragmentLayoutBinding;

import jp.wasabeef.glide.transformations.CropCircleTransformation;


/**
 * Created by zhang on 2017/1/6.
 * 我的
 */

public class MainMineFragment extends BaseFragment {

    private MinefragmentLayoutBinding mine;
    private RelativeLayout rl;
    private LinearLayout ly;
    private ImageView iv;
    private TextView tv;
    public static MainMineFragment getInstance(String type) {
        Bundle bundle = new Bundle();
        bundle.putString("type",type);
        MainMineFragment fragment = new MainMineFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mine = DataBindingUtil.inflate(inflater,R.layout.minefragment_layout,container,false);
        setOnClick();
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mine.rlMine.getLayoutParams();
        layoutParams.height = ScreenUtils.getScreenHeight(getActivity())/3;
        layoutParams.width  = ScreenUtils.getScreenWidth(getActivity());
        mine.rlMine.setLayoutParams(layoutParams);
        rl = mine.before;
        ly = mine.after;
        iv = mine.inLogin.ivAdd;
        tv = mine.inLogin.name;
        return mine.getRoot();
    }

    public void setOnClick(){
        mine.setMyClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()){
                    case R.id.iv_setting://设置
                        startActivityForResult(new Intent(getActivity(), SettingActivity.class),111);
                        break;
                    case R.id.tv_login://登录按钮
                        jumpLogin();
                        break;
                    case R.id.tv_zuji://我的足迹
                        if(MyApplication.isLogin){

                        }else{
                            jumpLogin();
                        }
                        break;
                    case R.id.tv_pinglun://我的评论
                        if(MyApplication.isLogin){

                        }else{
                            jumpLogin();
                        }
                        break;
                }
            }
        });

    }

    private void jumpLogin(){
        startActivityForResult(new Intent(getActivity(), LoginActivity.class),111);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == 111 && resultCode == 258){
            rl.setVisibility(View.GONE);
            ly.setVisibility(View.VISIBLE);
            tv.setText(data.getStringExtra("name"));
            Glide.with(getActivity().getApplicationContext()).load(data.getStringExtra("pic"))
                    .bitmapTransform(new CropCircleTransformation(
                            Glide.get(getActivity().getApplicationContext()).
                                    getBitmapPool())).into(iv);
        }
    }



    }

